<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>字符串反向器</title>
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            background: #f0f2f5;
            margin: 0;
        }

        .container {
            background: white;
            padding: 2rem;
            border-radius: 12px;
            box-shadow: 0 4px 12px rgba(0,0,0,0.1);
            width: 90%;
            max-width: 600px;
        }

        h1 {
            color: #2c3e50;
            text-align: center;
            margin-bottom: 2rem;
        }

        .input-group {
            margin: 1.5rem 0;
        }

        #inputText {
            width: 100%;
            padding: 12px;
            font-size: 16px;
            border: 2px solid #bdc3c7;
            border-radius: 6px;
            transition: border-color 0.3s ease;
        }

        #inputText:focus {
            border-color: #3498db;
            outline: none;
        }

        button {
            width: 100%;
            padding: 12px;
            background: #3498db;
            color: white;
            border: none;
            border-radius: 6px;
            cursor: pointer;
            font-size: 16px;
            transition: background 0.3s ease;
        }

        button:hover {
            background: #2980b9;
        }

        #result {
            margin-top: 1.5rem;
            padding: 1rem;
            border-radius: 6px;
            font-size: 18px;
            word-break: break-all;
        }

        .success {
            background: #e8f6ff;
            color: #2c3e50;
            border: 1px solid #3498db;
        }

        .error {
            background: #f8d7da;
            color: #721c24;
            border: 1px solid #f5c6cb;
            margin-top: 1rem;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>字符串反向转换器</h1>
        
        <div class="input-group">
            <input type="text" id="inputText" placeholder="请输入要反转的字符串">
        </div>

        <button onclick="reverseString()">立即反转</button>

        <div id="result" class="success" style="display: none;"></div>
        <div id="error" class="error" style="display: none;"></div>
    </div>

    <script>
        function reverseString() {
            // 获取元素引用
            const inputField = document.getElementById('inputText');
            const resultDiv = document.getElementById('result');
            const errorDiv = document.getElementById('error');

            // 重置状态
            errorDiv.style.display = 'none';
            resultDiv.style.display = 'none';

            // 获取输入值并验证
            const inputStr = inputField.value.trim();
            
            if (!inputStr) {
                errorDiv.textContent = "⚠ 请输入有效内容！";
                errorDiv.style.display = 'block';
                return;
            }

            // 执行反转操作
            const reversedStr = inputStr.split('').reverse().join('');

            // 显示结果
            resultDiv.innerHTML = `
                <div style="margin-bottom: 8px;">原始字符串：${inputStr}</div>
                <div style="font-weight: bold;">反转结果：${reversedStr}</div>
            `;
            resultDiv.style.display = 'block';
        }
    </script>
</body>
</html>